<tc_include file="Public:head"/>
<body ontouchstart style="background: #ebebeb;">
<div class="container" id="container">
    <div class="page">
        <div class="page__bd" style="height: 100%; overflow: hidden;">
            <div class="weui-tab">
                <div class="weui-tab__panel">
                    <div class="reg-box">
                        <!--注册-->
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">手机号</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="mobile" class="weui-input" type="tel" placeholder="请输入手机号">
                                </div>
                            </div>
                            <div class="weui-cell weui-cell_vcode">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">验证码</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="vcode" class="weui-input" type="number" placeholder="请输入获取验证码">
                                </div>
                                <div class="weui-cell__ft">
                                    <button class="weui-vcode-btn">获取验证码<span>send me security code</span></button>
                                </div>
                            </div>
                            <div class="weui-cell">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">密码</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="password" class="weui-input" type="password" placeholder="">
                                </div>
                                <div class="weui-cell__ft">
                                    <span>6位以上数字及密码</span>
                                </div>
                            </div>
                        </div>
                        <div class="weui-btn-area">
                            <a class="weui-btn weui-btn_default" href="javascript:"
                               id="regBtn">提交注册<br/><span>submit</span></a>
                        </div>

                        <div class="weui-cells__tips text-center">
                            点击提交，即表示已阅读并同 <a href="#">《夏都小镇会员服务条款》</a><br/>
                            <span>I have read and accepted <a
                                    href="#">Lido Way Membership Terms and Conditions</a></span>
                        </div>
                        <!--注册 end-->
                    </div>
                </div>
                <tc_include file="Public:menu"/>
            </div>
        </div>
    </div>
</div>

<div id="dialogs">
    <!--BEGIN regDialog-->
    <div class="js_dialog" id="regDialog" style="display: none;">
        <div class="weui-mask"></div>
        <div class="weui-dialog notice-dialog">
            <div class="weui-dialog__btn">&times;</div>
            <div class="icon-box">
                <i class="icon iconfont icon-notice"></i>
            </div>
            <div class="weui-dialog__bd">
                <div class="weui-dialog__title">注册成功！</div>
                <p>欢迎加入夏都小镇，<font>即将跳转会员页面！</font></p>
            </div>
        </div>
    </div>
    <!--END regDialog-->
</div>
<tc_include file="Public:footer"/>
<script type="text/javascript">

    function show_dialog(code,title,content) {
        if(code==200){
            $(".weui-dialog__bd .weui-dialog__title").html("注册成功！");
            $(".weui-dialog__bd p").html("欢迎加入夏都小镇，<font>即将跳转会员页面！</font>");
        }
        else{
            $(".weui-dialog__bd .weui-dialog__title").html(title);
            $(".weui-dialog__bd p").html(content);
        }
        $('#regDialog').fadeIn(0);
    }



    $(function () {

        $(".weui-vcode-btn").on('click',function () {
            var mobile = $("#mobile").val();
            var isMobile = /^(1+\d{10})$/;
            if(!isMobile.exec(mobile)){
                show_dialog(0,'发送验证码失败！','请输入正确的手机号');
                return false;
            }


            $.post('{:U("Public/sendvcode")}', {mobile: mobile}, function (data) {

                if (data.code == 200) {
                    show_dialog(0,'发送验证码成功！','');
                } else {
                    show_dialog(data.code, '发送失败！', data.message);
                }
            });

        });

        //注册成功
        $('#regBtn').on('click', function () {

            var mobile = $("#mobile").val();
            var vcode = $("#vcode").val();
            var password = $("#password").val();

            var isMobile = /^(1+\d{10})$/;
            var isvcode = /^(\d{5})$/;
            var isPassword = /^[0-9a-zA-Z_]{6,15}$/;

            if(!isMobile.exec(mobile)){
                show_dialog(0,'注册失败！','请输入正确的手机号');
                return false;
            }
            if(!isvcode.exec(vcode)){
                show_dialog(0,'注册失败！','请输入正确的验证码');
                return false;
            }
            if(!isPassword.exec(password)){
                show_dialog(0,'注册失败！','请输入6位以上数字及密码');
                return false;
            }


            $.post('{:U("public/doRegister")}', {mobile: mobile, vcode: vcode, password: password}, function (data) {

                if (data.code == 200) {
                    show_dialog(200);
                    setTimeout(function(){
                        location.href = "{:U('member/index')}";
                    }, 2000);
                } else {
                    show_dialog(data.code, '注册失败！', data.message);
                }
            });

        });
        //关闭dialogs
        $('#dialogs').on('click', '.weui-dialog__btn', function () {
            $(this).parents('.js_dialog').fadeOut(0);
        });


    });
</script>
